/*
Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.

Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.

For the purpose of this problem, we define empty string as valid palindrome.
*/

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <sstream>
#include "print.h"
using namespace std;

/**
* Definition for binary tree*/


void testForStack()
{
	stack<int> mystack;
	mystack.push(10);
	mystack.push(20);
	mystack.top() -= 5;
	cout << "mystack.top() is now " << mystack.top() << endl;
}

void testForIntToString()
{
	int a = 10;
	stringstream ss;
	ss << a;
	string str = ss.str();
	cout << str << endl;

	string str1 = to_string(a);

}





class Solution {
public:
	bool isPalindrome(string s) {
		if (s.empty())
			return true;

		transform(s.begin(), s.end(), s.begin(), tolower);
		auto left = s.begin(), right = prev(s.end());
		while (left < right) {
			if (!::isalnum(*left)) ++left;
			else if (!::isalnum(*right)) --right;
			else if (*left != *right) return false;
			else{ left++, right--; }
		}
		return true;
	}
};

class Solution2 {
public:
	bool isPalindrome(string s) {
		if (s.empty())
			return true;

		transform(s.begin(), s.end(), s.begin(), tolower);


		for (int i = 0, j = s.size() - 1; i < j;)
		{
			if (isalnum(s[i])) ++i;
			else if (isalnum(s[j]))
			{
				j--;
			}
			else if (s[i] != s[j])
			{
				return false;
			}
			else
			{
				i++;
				j--;
			}
		}
		return true;
	}
};

int main(int argc, char* argv[])
{


	int a = 0;
	
	for (int i = 1; i < argc; i++){


		cout << argv[i] << endl;
		a = atoi(argv[i]);
	}



	string str1= "A man, a plan, a canl:";



	Solution s;
	//stackTree.push(p->left);
	//stackTree.push(p->right);
	if (s.isPalindrome(str1))
		cout << " True" << endl;
	else
		cout <<"false" << endl;
	system("pause");
	return 0;
}